import sqlite3
import argparse
from pathlib import Path

def restore_backup(backup_path, target_path):
    backup = sqlite3.connect(backup_path)
    target = sqlite3.connect(target_path)
    
    try:
        backup.backup(target)
        print(f"成功恢复到 {target_path}")
    except sqlite3.Error as e:
        print(f"恢复失败: {e}")
    finally:
        backup.close()
        target.close()

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--backup", required=True, help="备份文件路径")
    parser.add_argument("--target", required=True, help="目标数据库路径")
    args = parser.parse_args()
    
    restore_backup(args.backup, args.target)